<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>开单页面</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/resources/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/resources/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <script src="/resources/js/echarts.min.js"></script>
    <link rel="stylesheet" href="/resources/css/amazeui.min.css"/>
    <link rel="stylesheet" href="/resources/css/amazeui.datatables.min.css"/>
    <link rel="stylesheet" href="/resources/css/app.css">
    <script src="/resources/js/jquery.min.js"></script>

    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="http://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <style type="text/css">
      body input{border-bottom:0}
    </style>
</head>

<body data-type="widgets">
<script src="/resources/js/theme.js"></script>
<div class="am-g tpl-g">
    <%--头部开始--%>
    <%@include file="header.jsp" %>
    <%--头部结束--%>


    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf" style="font-size: 11px;">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">开单流程第三步</div>
                            <small>会诊、处方开具</small>
                        </div>

                        <div class="widget-body  am-fr">

                            <!-- 编辑栏 -->
                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                <div class="am-form-group">
                                    <div class="am-btn-toolbar">
                                        <div class="am-btn-group am-btn-group-xs">
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- 下拉框 -->
                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                            </div>
                            <!-- 搜索框 -->
                            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                </div>
                            </div>
                            <script>
                                // $("body").keydown(function () {
                                //     var hasFocus = $('#searchContent').is(':focus');
                                //     if (event.keyCode == "13") {//keyCode=13是回车键
                                //         if (hasFocus == true) {
                                //             searchInfo();
                                //         } else {
                                //             alert("全局")
                                //         }
                                //     }
                                // });

                                function checkValue(type, content) {
                                    if (content === null || content === undefined || content === '' || content.length === 0) {
                                        return false;
                                    }
                                    // var phoneRex = /^1[34578]\d{9}$/;
                                    var phoneRex = /^\d{3,}$/;
                                    var otherRex = /^\w+$/;
                                    var otherRex1 = /^[\u2E80-\u9FFF]+$/;
                                    if (content.length > 200) {
                                        alert("输入的数据过长");
                                        return false;
                                    }
                                    if (type == "phone") {
                                        //电话号码校验
                                        if (phoneRex.test(content)) {
                                            return true;
                                        } else {
                                            alert("请输入三个以上的数字")
                                        }
                                    } else {
                                        if (otherRex.test(content) || otherRex1.test(content)) {
                                            return true;
                                        } else {
                                            alert("请输入正确的信息")
                                        }
                                    }
                                    return false;
                                }

                                function setValue(res) {
                                    //纸质档案编号
                                    $("#fileNo").attr("value", res.babyInfo.fileNo);
                                    //宝宝姓名
                                    $(".babyName").attr("value", res.babyInfo.babyName);
                                    //宝宝图片
                                    $(".imagePhoto").attr("src", res.babyInfo.babyPhoto);
                                    //宝宝性别
                                    $(".babySex").val(res.babyInfo.babySex);
                                    //是否早产
                                    $(".premature").val(res.babyInfo.premature);
                                    //宝宝年龄
                                    $(".babyAge").attr("value", res.babyInfo.babyAge);
                                    //宝宝身高
                                    $(".babyHeight").attr("value", res.babyInfo.babyHeight);
                                    //宝宝体重
                                    $(".babyWeight").attr("value", res.babyInfo.babyWeight);
                                    //宝宝出生日期
                                    var time = new Date(res.babyInfo.babybirthday);
                                    var year = time.getFullYear();
                                    var month = time.getMonth() + 1;
                                    var date = time.getDate();
                                    var t = year + "-" + month + "-" + date;
                                    $(".birthday").attr("value", t);
                                    //喂养史
                                    // $(".feedHistory").attr("value",res.babyInfo.feedHistory);
                                    $(".feedHistory").val(res.babyInfo.feedHistory);
                                    //过敏史
                                    $(".allergyHistory").val(res.babyInfo.allergyHistory);
                                    //病史
                                    $(".sickHistory").val(res.babyInfo.sickHistory);
                                    //备注
                                    $(".babyNote").val(res.babyInfo.babyNote);
                                    //会员卡类型
                                    $(".vipcategory").val(res.vipCard.vipName);
                                    //会员卡号码
                                    $(".vipNo").val(res.vipInfo.vipNo);
                                    //父母姓名
                                    $(".pname").val(res.userInfo.userName);
                                    //父母电话
                                    $(".phone").val(res.userInfo.userTel);
                                    //卡余额或者剩余次数

                                    if (res.vipCard.vipLevel == 0) {
                                        //体验卡
                                        $(".vipSum").val("剩余" + res.vipInfo.remainTime + "次消费")
                                    } else {
                                        //其他会员等级的卡
                                        $(".vipSum").val("剩余" + res.vipInfo.balance + "元")
                                    }

                                }

                                function searchInfo() {
                                    var type = $("#searchType").val();
                                    var content = $("#searchContent").val();
                                    if (checkValue(type, content)) {
                                        var data = new FormData();
                                        data.append("type", type);
                                        data.append("content", content);
                                        var URL = "/process/search";
                                        $.ajax({
                                            url: URL,
                                            type: 'POST',
                                            cache: false,
                                            data: data,
                                            async: false,
                                            processData: false,
                                            contentType: false
                                        }).done(function (res) {
                                            console.log(res);
                                            $("#info").empty();
                                            for (var i = 0; i < res.length; i++) {
                                                var tmp = res[i];
                                                setValue(tmp);
                                                $("#info").prepend("<li><a class='searchOne' href=\"javascript:findOne(" + tmp.userInfo.id + ");\">" + "宝宝姓名：" + tmp.babyInfo.babyName + "&emsp;父母姓名：" + tmp.userInfo.userName + "&emsp;会员卡号：" + tmp.vipInfo.vipNo + "&emsp;电话号码：" + tmp.userInfo.userTel + "</a></li>");
                                            }
                                            console.log(res);
                                        }).fail(function (res) {
                                            console.log(res);
                                            alert("数据异常")
                                        });
                                    }

                                    //     console.log(type + "===" + content);

                                }

                                function findOne(id) {
                                    var data = new FormData();
                                    data.append("uid", id);
                                    var URL = "/process/one";
                                    $.ajax({
                                        url: URL,
                                        type: 'POST',
                                        cache: false,
                                        data: data,
                                        async: false,
                                        processData: false,
                                        contentType: false
                                    }).done(function (res) {
                                        console.log(res);
                                        $("#info").empty();
                                        if (res === null || res === undefined || res === '') {
                                            alert("该用户数据异常")
                                        } else {
                                            setValue(res);
                                        }
                                    }).fail(function (res) {
                                        console.log(res);
                                        alert("网络错误，请重新操作")
                                    });
                                }
                            </script>
                            <%--症状显示start--%>
                            <!-- 用户数据显示 -->

                        </div>
                        <%--症状显示end--%>
                        <div class="am-u-sm-12  am-u-md-3 am-u-lg-3" style="margin-top:30px;">
                            <!-- 宝宝姓名-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-3 am-form-label" style="padding-top: 5%">宝宝姓名</label>
                                <div class="am-u-sm-7">
                                    <input type="text" name="babyName" id="babyName"
                                           class="am-form-field tpl-form-no-bg babyName"
                                           placeholder="" maxlength="4" readonly/>
                                </div>

                            </div>
                            <!-- 宝宝性别===性别校验-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-md-2 am-u-lg-3 am-form-label" style="padding-top: 5%">宝宝性别</label>
                                <div class="am-u-sm-7">
                                        <input type="text" id="babySex" name="premature"
                                               class="am-form-field tpl-form-no-bg babySex"
                                               placeholder="" readonly/>
                                </div>
                            </div>
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-md-2 am-u-lg-3 am-form-label" style="padding-top: 5%">是否早产</label>
                                <div class="am-u-sm-7">
                                        <input type="text" id="premature" name="premature"
                                               class="am-form-field tpl-form-no-bg babyAge"
                                               placeholder="" readonly/>
                                </div>
                            </div>

                            <!-- 宝宝年龄-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-3 am-form-label" style="padding-top: 5%">宝宝年龄</label>
                                <div class="am-u-sm-7">
                                    <input type="text" id="babyAge" name="babyAge"
                                           class="am-form-field tpl-form-no-bg babyAge"
                                           placeholder="" readonly/>
                                </div>

                            </div>

                            <!-- 宝宝体重-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-3 am-form-label" style="padding-top: 5%">宝宝体重</label>
                                <div class="am-u-sm-7">
                                    <input type="text" id="babyWeight" name="babyWeight"
                                           class="am-form-field tpl-form-no-bg babyWeight"
                                           placeholder="" maxlength="4" readonly/>
                                </div>

                            </div>

                            <!-- 宝宝身高-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-3 am-form-label" style="padding-top: 5%">宝宝身高</label>
                                <div class="am-u-sm-7">
                                    <input type="text" name="babyHeight" id="babyHeight"
                                           class="am-form-field tpl-form-no-bg babyHeight"
                                           placeholder="" maxlength="3" readonly/>
                                </div>

                            </div>

                            <!-- 喂养史-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-4 am-u-md-4 am-u-lg-4 am-form-label" style="padding-top: 7%">喂养史</label>
                                <div class="am-u-sm-8  am-u-md-8 am-u-lg-8">
                                    <textarea name="feedHistory" id="feedHistory"
                                              class="am-form-field tpl-form-no-bg feedHistory"
                                              placeholder="" maxlength="200" readonly></textarea>
                                </div>

                            </div>

                            <!-- 过敏史-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-4 am-form-label" style="padding-top: 7%">过敏史</label>
                                <div class="am-u-sm-8">
                                    <textarea name="allergyHistory" id="allergyHistory"
                                              class="am-form-field tpl-form-no-bg allergyHistory"
                                              placeholder="" maxlength="200" readonly></textarea>
                                </div>
                            </div>

                            <!-- 病史-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-4 am-form-label" style="padding-top: 7%">病史</label>
                                <div class="am-u-sm-8">
                                    <textarea name="sickHistory" id="sickHistory"
                                              class="am-form-field tpl-form-no-bg sickHistory"
                                              placeholder="" maxlength="200" readonly></textarea>
                                </div>
                                <div class="am-u-sm-2">
                                </div>
                            </div>
                            <!-- 会员卡名称-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-4 am-form-label" style="padding-top: 7%">会员卡名称</label>
                                <div class="am-u-sm-8">
                                    <textarea id="vipCard" name="vipCard" class="am-form-field tpl-form-no-bg vipCard"
                                              placeholder="" maxlength="200" readonly></textarea>
                                </div>
                            </div>
                            <!-- 备注-->
                            <div class="am-u-md-12 am-u-lg-12">
                                <label class="am-u-sm-4 am-form-label" style="padding-top: 7%">备注</label>
                                <div class="am-u-sm-8">
                                    <textarea id="notes" name="babyNote" class="am-form-field tpl-form-no-bg babyNote"
                                              placeholder="" maxlength="200" readonly></textarea>
                                </div>
                            </div>
                            <div class="am-u-sm-12  am-u-md-12 am-u-lg-12" id="sysPtdom-detail" style="height: 40px"></div>
                        </div>

                        <div class="am-u-sm-12 am-u-md-9 am-u-lg-9" style="margin-top: 30px;">
                            <div class="am-u-sm-12 am-u-md-12 am-u-lg-12" id="detail-content"></div>
                            <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                                <div class="am-u-sm-12  am-u-md-12 am-u-lg-12">
                                    <div class="am-u-sm-12  am-u-md-12 am-u-lg-12" style="margin-top: 15px;padding-left: 0px">
                                        <label class="am-u-sm-2 am-u-lg-2 am-form-label">引用模板</label>
                                        <label class="am-radio-inline">
                                            <input type="radio" name="template" class="is" value="1" checked="checked"> 商品
                                        </label>
                                        <label class="am-radio-inline">
                                            <input type="radio" name="template" class="is" value="2"> 穴位
                                        </label>
                                        <label class="am-radio-inline">
                                            <input type="radio" name="template" class="is" value="3" checked="checked"> 商品模板
                                        </label>
                                        <label class="am-radio-inline">
                                            <input type="radio" name="template" class="is" value="4"> 穴位模板
                                        </label>
                                    </div>
                                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                                        <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                            <input type="text" id="searchContent" placeholder="请输入商品名或者商品编号" class="am-form-field">
                                            <span class="am-input-group-btn">
                                                <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"
                                                    type="button" id="searchinfoBtn"></button>
                                            </span>
                                        </div>
                                    </div>
                                    <div id="checkedTable" class="am-u-sm-12 am-u-md-12 am-u-lg-12" style="min-height: 30px">

                                    </div>
                                    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                                        <table class="am-u-sm-12 am-u-lg-12 am-table am-table-bordered am-table-compact tpl-table-black" style="padding-left: 0px">
                                            <tr>
                                                <td>
                                                    处方总价格
                                                </td>
                                                <td id="purchPrice"></td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    折后价格
                                                </td>
                                                <td id="vipPrice"></td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    会员余额
                                                </td>
                                                <input type="hidden" id="priceID" name="reserve4" >
                                                <td id="vipMoney"></td>
                                            </tr>
                                        </table>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12" style="text-align: center;">
                                    <button type="button" class="am-btn am-btn-warning" style="margin: auto; padding: auto;margin-bottom: 15px" id="computePrice">计算价格</button>
                                </div>
                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">

                                    <div class="am-u-sm-6 am-avg-md-9 am-u-lg-9">
                                        <%--添加出的标签--%>
                                        <select class="" id="noticeDetail" name="noticeDetail" multiple data-am-selected="{btnWidth: '100%', maxWidth:200}">
                                            <!-- 动态加载数据 -->
                                        </select>
                                    </div>
                                </div>
                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                                    <%--<label class="am-u-sm-6 am-u-md-2 am-u-lg-2 am-form-label"></label>--%>
                                    <div class="am-u-sm-6 am-avg-md-9 am-u-lg-9">
                                        <%--添加出的标签--%>
                                        <input type="text" id="noteText"  class="am-form-field am-input-group am-input-group-sm tpl-form-border-form cl-p" style="min-height:30px;border: 1px solid #c2cad8;width: 100%" placeholder="请输入自定义注意事项" >
                                    </div>
                                </div>
                                <label class="am-u-sm-2 am-u-lg-2 am-form-label"></label>
                                <div class="am-u-md-12 am-u-lg-12">
                                    <div class="am-u-lg-offset-2  am-u-sm-7">
                                        <textarea id="pre_result" class="am-form-field tpl-form-no-bg"
                                                  placeholder="请输入诊断结果" maxlength="800" style="height: 80px;border: 1px solid #c2cad8"></textarea>
                                    </div>
                                </div>
                                <div class="am-u-md-4 am-u-lg-6">
                                    <div class="am-form-group">
                                        <label class="am-radio-inline">
                                            <input type="radio" name="is" class="is" value="0" checked="checked"> 不进入会诊中心
                                        </label>
                                        <label class="am-radio-inline">
                                            <input type="radio" name="is" class="is" value="1"> 进入会诊中心
                                        </label>
                                    </div>
                                </div>
                                <div class="am-u-sm-12  am-u-md-12 am-u-lg-12" style="height: 20px;font-size:30px">


                                </div>
                                <!-- 按钮 -->
                                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                                    <div class="am-u-sm-7 am-u-sm-push-5">
                                        <button type="button" href="javascript: void(0)" id="restBaby"
                                                class="am-btn am-btn-default tpl-btn-bg-color-success am-u-sm-5">重新采集数据
                                        </button>
                                        <button type="button" href="javascript: void(0)" id="submitAddBaby"
                                                class="am-btn am-btn-primary tpl-btn-bg-color-success am-u-sm-5">下一步
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<%--开方模态框start--%>
<div class="am-modal tpl-am-model-bd" id="pre-model">
    <div class="am-modal-dialog">
        <div class="am-modal-hd row">
            <h2>模板选择</h2><a id="modal-close" class="am-close am-close-spin">&times;</a>
        </div>

        <%--<div class="am-u-sm-12 am-u-lg-12 modal-input-div">--%>
        <table class="am-u-sm-12 am-u-lg-12 am-table am-table-bordered am-table-compact tpl-table-black"
               id="typePromenu" style="color: #333">
            <tr>
                <td>
                   选择
                </td>
                <td>内容</td>
                <td>
                   价格
                </td>
            </tr>
        </table>
        <%--</div>--%>
        <button type="button" id="addBtnpro" class=" am-u-md-12  am-btn am-btn-primary" style="margin-top: 10px">添加
        </button>
    </div>
</div>
<%--开方模态框--%>



<!-- 图片显示模态框 -->
<div class="am-modal am-modal-no-btn" tabindex="-1" id="sysType_enter">
    <div class="am-modal-dialog" style="width:700px;height:500px;">
        <div class="am-modal-bd">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">照片显示</div>
                            <div class="widget-function am-fr">
                                <a href="javascript: void(0)" class="am-close am-close-spin close_a"
                                   data-am-modal-close>&times;</a>
                            </div>
                        </div>
                        <div class="widget-body am-fr">
                            <form class="am-form tpl-form-border-form tpl-form-border-br">
                                <div id="myCarousel" class="carousel slide" style="width:100%;height:100%;margin:auto;">
                                    <!-- 轮播（Carousel）项目 -->
                                    <div class="carousel-inner">
                                        <!-- <div class="item active">
                                            <img class="firstimg"  src="" style="width:280px;height:250px;margin:auto 10px;" alt="照片">
                                        </div> -->
                                    </div>
                                    <!-- 轮播（Carousel）导航 -->
                                    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
                                        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
                                        <span class="sr-only">Previous</span>
                                    </a>
                                    <a class="right carousel-control" href="#myCarousel" role="button"
                                       data-slide="next">
                                        <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                                        <span class="sr-only">Next</span>
                                    </a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 模态框 -->


<script src="/resources/js/amazeui.min.js"></script>
<script src="/resources/js/amazeui.datatables.min.js"></script>
<script src="/resources/js/dataTables.responsive.min.js"></script>
<script src="/resources/js/app.js"></script>
<script>

    //  单击事件
    $('#searchinfoBtn').dblclick(
        function () {
            console.log("双击事件");
            $('#pre-model').modal({target: '#pre-model', width: 800});
        }
    );

    //  单击事件
    $('#searchinfoBtn').click(
        function () {
            $("#typePromenu tr:not(:first)").html("");
            console.log("单击事件");
            var radioVal = $('input[name="template"]:checked').val();
            var formdata = new FormData();
            var templateTable = '';
            var searchValue = $("#searchContent").val();
            switch (radioVal){
                case "1" :
                    formdata.append("productNo",searchValue);
                    formdata.append("reserve1",searchValue);
                    $.ajax({
                        url: "/process/searchProduct",
                        type: 'POST',
                        data: formdata,
                        cache: false,
                        async: false,
                        processData: false,
                        contentType: false
                    }).done(function (res){
                        for ( var i = 0 ; i < res.productList.length ; i++){
                            templateTable ='<tr><td><input type="checkbox" name="productTemplate" data-temId="0" data-price="'+res.productList[i].unitPrice+'" data-type="dietary" data-count="1" value="'+res.productList[i].productId+'"></td><td>'+res.productList[i].reserve1+'</td><td>'+ res.productList[i].unitPrice +'元</td></tr>';
                            $('#typePromenu').append(templateTable);
                        }
                    });
                    break;
                case "2" :
                    formdata.append("acupNo",searchValue);
                    formdata.append("acupName",searchValue);
                    $.ajax({
                        url: "/process/searchAcupByOneTarget",
                        type: 'POST',
                        data: formdata,
                        cache: false,
                        async: false,
                        processData: false,
                        contentType: false
                    }).done(function (res){
                        for ( var i = 0 ; i < res.acupList.length ; i++){
                            templateTable ='<tr><td><input type="checkbox" name="productTemplate" data-temId="0" data-price="20" data-type="dietary" data-count="1" value="'+res.acupList[i].acupId+'"></td><td>'+res.acupList[i].acupName+'</td><td>20元</td></tr>';
                            $('#typePromenu').append(templateTable);
                        }
                    });
                    break;
                case "3" :
                    alert("模板不支持搜索");
                    break;
                case "4" :
                    alert("模板不支持搜索");
                    break;
            }
            $('#pre-model').modal({target: '#pre-model', width: 800});
        }
    );

//双击搜索框默认搜索所有
    $('#searchContent').dblclick(
        function () {
            $("#typePromenu tr:not(:first)").html("");
            console.log("input双击事件");
            var url = "/process/getTemplate";
            var radioVal = $('input[name="template"]:checked').val();
            var formdata = new FormData();
            var templateTable = '';
            switch (radioVal){
                case "1" :
                    formdata.append("reserve2",'${illCase.illCaseId}');
                    $.ajax({
                        url: "/templateEntryController/findProduct",
                        type: 'POST',
                        data: formdata,
                        cache: false,
                        async: false,
                        processData: false,
                        contentType: false
                    }).done(function (res){
                        for ( var i = 0 ; i < res.productList.length ; i++){
                            templateTable ='<tr><td><input type="checkbox" name="productTemplate" data-temId="0" data-price="'+res.productList[i].unitPrice+'" data-type="dietary" data-count="1" value="'+res.productList[i].productId+'"></td><td>'+res.productList[i].reserve1+'</td><td>'+ res.productList[i].unitPrice +'元</td></tr>';
                            $('#typePromenu').append(templateTable);
                        }
                    });
                    break;
                case "2" :
                    $.ajax({
                        url: "/templateEntryController/findAcupuncturePoint",
                        type: 'POST',
                        data: formdata,
                        cache: false,
                        async: false,
                        processData: false,
                        contentType: false
                    }).done(function (res){
                        var Prices = [];
                        for ( var i = 0 ; i < res.acupList.length ; i++){
                            templateTable ='<tr><td><input type="checkbox" name="productTemplate" data-temId="0" data-type="nurse" data-price="20" data-count="1" value="'+res.acupList[i].acupId+'"></td><td>'+res.acupList[i].acupName+'</td><td>20元</td></tr>';
                            $('#typePromenu').append(templateTable);
                        }
                    });
                    break;
                case "3" :
                    formdata.append("temType","dietary");
                    $.ajax({
                        url: url,
                        type: 'POST',
                        data: formdata,
                        cache: false,
                        async: false,
                        processData: false,
                        contentType: false
                    }).done(function(res){
                        for (var i = 0 ; i < res.length ; i++){
                            var temdetails = eval(res[i].temDetail);
                            var Reids = [];
                            var ProductCounts = [];
                            var Prices = [];
                            for(var k = 0 ; k < temdetails.length ; k++){
                                Reids.push(temdetails[k].Reid);
                                ProductCounts.push(temdetails[k].productCount);
                                Prices.push(temdetails[k].price);
                            }
                            var pronames = "";
                            templateTable ='<tr><td><input type="checkbox" name="productTemplate" data-temId="'+res[i].temId+'" data-type="dietary" data-price="'+Prices+'" data-count="'+ProductCounts+'" value="'+Reids+'"></td><td id="proname'+i+'"></td><td>'+ res[i].temSumPrice +'元</td></tr>';
                            $('#typePromenu').append(templateTable);
                            for(var j = 0 ; j < temdetails.length ; j++){
                                console.log(temdetails[j].Reid);
                                var productTempalate = findProductById(temdetails[j].Reid);
                                var temstr = productTempalate.proName+"："+temdetails[j].productCount+productTempalate.measureway+",";
                                pronames += temstr;
                            }
                            pronames = pronames.substring(0,pronames.length-1);
                            var proid = 'proname'+i;
                            $("#"+proid+"").append(pronames);
                        }
                    });
                    break;
                case "4" :
                    formdata.append("temType","nurse");
                    $.ajax({
                        url: url,
                        type: 'POST',
                        data: formdata,
                        cache: false,
                        async: false,
                        processData: false,
                        contentType: false
                    }).done(function(res){
                        for (var i = 0 ; i < res.length ; i++){
                            var temdetails = eval(res[i].temDetail);
                            var Reids = [];
                            var ProductCounts = [];
                            var Prices = [];
                            for(var k = 0 ; k < temdetails.length ; k++){
                                Reids.push(temdetails[k].Reid);
                                ProductCounts.push(temdetails[k].productCount);
                                Prices.push(temdetails[k].price);
                            }
                            var pronames = "";
                            templateTable ='<tr><td><input type="checkbox" name="productTemplate" data-temId="'+res[i].temId+'" data-type="nurse" data-price="'+Prices+'" data-count="'+ProductCounts+'" value="'+Reids+'"></td><td id="proname'+i+'"></td><td>'+ res[i].temSumPrice +'元</td></tr>';
                            $('#typePromenu').append(templateTable);
                            for(var j = 0 ; j < temdetails.length ; j++){
                                console.log(temdetails[j].Reid);
                                var productTempalate = findPointById(temdetails[j].Reid);
                                var temstr = productTempalate.proName+"："+temdetails[j].productCount+productTempalate.measureway+",";
                                pronames += temstr;
                            }
                            pronames = pronames.substring(0,pronames.length-1);
                            var proid = 'proname'+i;
                            $("#"+proid+"").append(pronames);
                        }
                    });
                    break;
            }

            $('#pre-model').modal({target: '#pre-model', width: 800});

        }
    );

    $('#addBtnpro').click(function(){
       addProduct();
    });

    function addProduct(){
        var checkBoxValue = getCheckboxVal();
        console.log(checkBoxValue.reid);
        console.log(checkBoxValue.rcount);
        console.log(checkBoxValue.dataType);
        for (var i = 0 ; i < checkBoxValue.reid.length ; i++){
            var reidString = checkBoxValue.reid[i];
            var reid_result = reidString.split(",");
            var countString = checkBoxValue.rcount[i];
            var count_result = countString.split(",");
            var typeString = checkBoxValue.dataType[i];
            var type_result = typeString.split(",");
            var priceString = checkBoxValue.dataPrice[i];
            var price_result = priceString.split(",");
            var temIdString = checkBoxValue.dataTemId[i];
            var temId_result = temIdString.split(",");
            for (var j = 0 ;j < reid_result.length ; j++){
                var productDetail;
                var flag = true;
                switch (type_result[0]){
                    case "dietary" :
                        productDetail = findProductById(reid_result[j]);
                        var tempname;
                        $(".countList").each(function(){
                            tempname = $(this).data("name");
                            if(tempname==undefined){
                                return false;
                            }else {
                                if(tempname == productDetail.proName){
                                    var tempCount = parseInt($(this).val())+parseInt(count_result[j]);
                                    $(this).val(tempCount);
                                    var reid = $(this).data("reid");
                                    var details = findProductById(reid);
                                    $(this).parent().children("input.unitPrice").val(details.unitPrice);
                                    flag = false;
                                }
                            }
                        });
                        if(flag){
                            console.log(productDetail.proName);
                            var divId = "product"+reid_result[j];
                            var temName = productDetail.proName;
                            var oneproduct = '<div class="am-btn am-btn-secondary am-round " id="'+divId+'" style="margin: 2px;"><span>'
                                + productDetail.proName +
                                '</span><input type="text" name="countList" data-name="'+productDetail.proName+'" data-reid="'+reid_result[j]+'" value="'+count_result[j]+'" class="countList" style="width:60px;height:25px;color:#000;display:inline-block;vertical-align:top;">'
                                + productDetail.measureway + "/" + "单价" + '<input type="text" readonly value=' + price_result[j] + ' style="width:60px;height:25px;display:inline-block;vertical-align:top;color:#000;" class="unitPrice">' + ' 元' + '<input type="hidden" data-measureway="'+productDetail.measureway+'" data-reid="'+ reid_result[j] +'" data-name="'+productDetail.proName+'" value="'+type_result[0]+'" data-temId="'+temId_result[0]+'" class="typeList"><div class="widget-function am-fr">\n' +
                                '                                <a onclick="removeProduct(this)" class="am-close am-close-spin close_a"\n' +
                                '                                   data-am-modal-close>&times;</a>\n' +
                                '                            </div></div>';
                            $('#checkedTable').append(oneproduct);
                            if(temId_result[0]>0){
                                $(".countList").addClass("temCountList")
                                $(".temCountList").bind("change",function(){
                                    var reid = $(this).data("reid");
                                    var details = findProductById(reid);
                                    $(this).parent().children("input.unitPrice").val(details.unitPrice);
                                });
                            }
                        }
                        break;
                    case "nurse" :
                        productDetail = findPointById(reid_result[j]);
                        var tempname;
                        $(".countList").each(function(){
                            tempname = $(this).data("name");
                            if(tempname==undefined){
                                return false;
                            }else {
                                if(tempname == productDetail.proName){
                                    var tempCount = parseInt($(this).val())+parseInt(count_result[j]);
                                    $(this).val(tempCount);
                                    flag = false;
                                }
                            }
                        });
                        if(flag){
                            console.log(productDetail.proName);
                            var divId = "product"+reid_result[j];
                            var oneproduct = '<div class="am-btn am-btn-secondary am-round  " id="'+divId+'" style="margin: 2px;"><span>'
                                + productDetail.proName +
                                '</span><input type="text" name="countList" data-name="'+productDetail.proName+'" value="'+count_result[j]+'" class="countList" style="width:60px;height:25px;color:#000;display:inline-block;vertical-align:top;">'
                                + productDetail.measureway + "/" + "单价" + '<input type="text"  value=' + price_result[j] + ' style="width:60px;height:25px;display:inline-block;vertical-align:top;color:#000;" class="unitPrice">' + ' 元' + '<input type="hidden" data-measureway="'+productDetail.measureway+'" data-reid="'+ reid_result[j] +'" data-name="'+productDetail.proName+'" value="'+type_result[0]+'" data-temId="'+temId_result[0]+'" class="typeList"><div class="widget-function am-fr">\n' +
                                '                                <a onclick="removeProduct(this)" class="am-close am-close-spin close_a"\n' +
                                '                                   data-am-modal-close>&times;</a>\n' +
                                '                            </div></div>';
                            $('#checkedTable').append(oneproduct);
                        }
                        break;
                }

            }
        }
        $("#typePromenu tr:not(:first)").html("");
        $('#pre-model').modal('close');

        var total = getTotalPrice();

        $('#purchPrice').html(total.normalTotal);
        $("#vipPrice").html(total.vipTotal);
    }



    $("#computePrice").on("click",function(){
        var total = getTotalPrice();
        $("#purchPrice").html("");
        $("#purchPrice").html(total.normalTotal);
        $("#vipPrice").html("");
        $("#vipPrice").html(total.vipTotal);
        $('#priceID').val('')
        $('#priceID').val(total.vipTotal);
    });

    function getCheckboxVal(){
        var obj = document.getElementsByName("productTemplate");
        var check_val = [];
        var check_count = [];
        var check_type = [];
        var check_price = [];
        var check_temId = [];
        for(k in obj){
            if(obj[k].checked){
                check_val.push(obj[k].value);
                check_count.push(obj[k].getAttribute("data-count"));
                check_type.push(obj[k].getAttribute("data-type"));
                check_price.push(obj[k].getAttribute("data-price"));
                check_temId.push(obj[k].getAttribute("data-temId"));
            }
        }
        return {reid:check_val,rcount:check_count,dataType:check_type,dataPrice:check_price,dataTemId:check_temId};
    }

    $('#modal-close').click(function(){
        console.log("模态框关闭");
        $("#typePromenu tr:not(:first)").html("");
        $('#pre-model').modal('close');
    });

    function removeProduct(which){
        which.parentNode.parentNode.parentNode.removeChild(which.parentNode.parentNode);
        var total = getTotalPrice();
        $("#purchPrice").html("");
        $("#purchPrice").html(total.normalTotal);
        $("#vipPrice").html("");
        $("#vipPrice").html(total.vipTotal);
        $('#priceID').val('')
        $('#priceID').val(total.vipTotal);
    }

    function findProductById(reid){
        var formdata = new FormData();
        formdata.append("productId",reid);
        var url = "/process/getProduct";
        var proName;
        var measureway;
        var unitPrice;
        $.ajax({
            url: url,
            type: 'POST',
            data: formdata,
            cache: false,
            async: false,
            processData: false,
            contentType: false
        }).done(function(res){
            proName = res.pro.reserve1;
            measureway = res.pro.measureWay;
            unitPrice = res.pro.unitPrice;
        });
        return {proName:proName,measureway:measureway,unitPrice:unitPrice};
    }

    function findPointById(reid){
        var formdata = new FormData();
        formdata.append("acupid",reid);
        var proName;
        var measureway = "次";
        $.ajax({
            url: "/templateEntryController/findOneAcupuncturePoint",
            type: 'POST',
            data: formdata,
            cache: false,
            async: false,
            processData: false,
            contentType: false
        }).done(function(res){
           proName = res.acup.acupName;
        });
        return {proName:proName,measureway:measureway};
    }

    $(function () {
        var formdata = new FormData();
        formdata.append("sate",1);
        $.ajax({
            type: "POST",
            url: "/process/findAllNotice",
            data: formdata,
            cache: false,
            async: false,
            processData: false,
            contentType: false,
            success: function (data) {
                for (var i = 0; i < data.noticeList.length; i++) {
                    $("#noticeDetail").append("<option value=" + data.noticeList[i].noticeDetail + ">" + data.noticeList[i].noticeDetail + "</option>");
                }
            },
            error: function () {
                alert("服务器内部错误");
            }
        });
    });

    function JsonItem(precount,preprice,pretype,prename,premeasure,preid,pretemid) {
        this.precount = precount;
        this.preprice = preprice;
        this.pretype = pretype;
        this.prename = prename;
        this.premeasure = premeasure;
        this.preid = preid;
        this.pretemid = pretemid;
    }

    $("#submitAddBaby").click(function () {
        nextProcess();
    });

    function nextProcess(){
        var formdata = new FormData();
        var jsonarr = new Array();

        var countList = new Array();
        $(".countList").each(function () {
            countList.push($(this).val());

        });
        // 单价集合
        var priceList = new Array();
        $(".unitPrice").each(function () {
            priceList.push($(this).val());
        });
        //类型集合
        var typeList = new Array();
        $(".typeList").each(function () {
            typeList.push($(this).val());
        });
        // 名字集合
        var nameList = new Array();
        $(".typeList").each(function () {
           nameList.push($(this).data("name"));
        });
        // 计量单位集合
        var measurewayList = new Array();
        $(".typeList").each(function () {
            measurewayList.push($(this).data("measureway"));
        });
        //reid集合
        var reidList = new Array();
        $(".typeList").each(function () {
            reidList.push($(this).data("reid"));
        });
        //temid集合
        var temidList = new Array();
        $(".typeList").each(function () {
            temidList.push($(this).data("temid"))
        })

        var temSumPrice = $("#purchPrice").text();

        for (var i = 0 ; i < countList.length ; i++){
            var jsonItem = new JsonItem(countList[i],priceList[i],typeList[i],nameList[i],measurewayList[i],reidList[i],temidList[i]);
            var json = JSON.stringify(jsonItem);
            jsonarr.push(json);
        }

        var noticeData = $("#noticeDetail").val();

        var preresult = $("#pre_result").val();

        var radioVal = $('input[name="is"]:checked').val();
        var note = $('#noteText').val();
        console.log(jsonarr);
        var submitData = new FormData();
        submitData.append("illCaseId",id);
        submitData.append("presDetail",jsonarr.toString());
        submitData.append("reserve2",noticeData);
        submitData.append("reserve3",preresult);
        submitData.append("reserve1",temSumPrice);
        submitData.append("reserve5",radioVal);
        submitData.append("reserve4", $('#priceID').val());
        if (note !=""&& note!=undefined && note != null){
            submitData.append("reserve15",note);
        }
        switch (radioVal){
            case "0" :
                $.ajax({
                    url: "/process/addPrescription",
                    type: "POST",
                    data: submitData,
                    cache: false,
                    async: false,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    if ( res != undefined && res != null && res != ''){
                        if (res.success){
                            window.location.href='/illCaseController/getillcase?pn=1&status=4';
                        }
                        alert(res.data.isInsert);
                    }
                });
                break;
            case "1" :
                $.ajax({
                    url: "/process/addPrescription",
                    type: "POST",
                    data: submitData,
                    cache: false,
                    async: false,
                    processData: false,
                    contentType: false
                }).done(function (res) {
                    if ( res != undefined && res != null && res != ''){
                        if (res.success){
                            window.location.href='/illCaseController/getillcase?pn=1&status=3';
                        }
                        alert(res.data.isInsert);
                    }
                });
                break;
        }

    }

    var allInfo = new Array();
   var id = '${illCase.illCaseId}';
   // var id =21;
    $(function () {
        var URL = "/process/getillcasedetail";

        var formdata = new FormData();
        formdata.append("illCaseId", id);
/*        formdata.append("illCaseState", 1);*/
        $.ajax({
            url: URL,
            type: "POST",
            data: formdata,
            cache: false,
            async: false,
            processData: false,
            contentType: false
        }).done(function (res) {
            console.log(res);
            if (res == null || res == '' || res == undefined) {
                alert("该信息不存在！");
                window.location.href = '/process/third';
                return;
            }
         //   var sysmptoms = eval(res.sysmptom);
            var tt ="["+res.sysmptom+"]";
            console.log(tt);

            var sysmptoms =JSON.parse(tt);
            console.log(sysmptoms);
        //    var dital = $('#sysPtdom-detail');
            var dital = $('#detail-content');
            for (var i = 0; i < sysmptoms.length; i++) {
                //解析图片
                if (sysmptoms[i].domtype == 3) {
                    sysmptoms[i].index = i;
                    allInfo.push(sysmptoms[i]);
                    var sdiv = ' <div class="am-u-md-4 am-u-lg-4"><label class="am-u-sm-3 am-form-label">' + sysmptoms[i].sysmpinstruct + '</label>' +
                        '<a class="am-u-sm-7" id="' + sysmptoms[i].index + '" href="javascript: getImagesModel(' + sysmptoms[i].index + ')">点击查看图片</a>' +
                        '</div></div>';
                    dital.prepend(sdiv);
                } else {
                    var sysptom = sysmptoms[i];
                    var sdiv = ' <div  class="am-u-md-4 am-u-lg-4"><label class="am-u-md-3 am-form-label">' + sysptom.sysmpinstruct + '</label> <div class="am-u-sm-7">' +
                        ' <input type="text" class="am-form-field tpl-form-no-bg babyHeight" value="' + sysptom.value + '"readonly />' +
                        '</div></div>';
                    dital.prepend(sdiv);
                }
            }

            var babyData = new FormData();
            console.log(res);
            var burl = '/babyInfoController/findOneBabyInfo';
            babyData.append("babyId", res.babyId);
            console.log("宝宝信息");
            $.ajax({
                url: burl,
                type: "POST",
                data: babyData,
                cache: false,
                async: false,
                processData: false,
                contentType: false
            }).done(function (res) {
                console.log(res);
                setValue(res.bb);
            });


        }).fail(function (res) {
            alert("网络错误，请检查数据是否完整");
        });
        ;
    });

    function getImagesModel(dom) {
        var tmpInfo;
        for (var i = 0; i < allInfo.length; i++) {
            if (allInfo[i].index == dom) {
                tmpInfo = allInfo[i];
            }
        }
        if (tmpInfo != undefined && tmpInfo != undefined && tmpInfo != '') {
            var images = tmpInfo.value.split(",");
            $(".carousel-inner").empty();
            for (var j = 0; j < images.length; j++) {
                if (j == 0) {
                    var first_div = '<div class="item active"><img class="firstimg" src="' + images[j] + '"style="width:660px;height:360px;margin:auto;" alt="照片"></div>';
                    $(".carousel-inner").append(first_div);
                } else {
                    var div = '<div class="item"><img src="' + images[j] + '"style="width:660px;height:360px;margin:auto;" alt="照片"></div>';
                    $(".carousel-inner").append(div);
                }
            }
            $('#sysType_enter').modal({closeViaDimmer: 0});
        } else {
            alert("数据异常");
        }
    }


    function setValue(obj) {
        $('#babyName').val(obj.babyName);
        if (obj.babySex==1){
            $('#babySex').val('男');
        }else {
            $('#babySex').val('女');
        }
        //是否早产
        if (obj.premature==1){
            $('#premature').val('是');
        } else {
            $('#premature').val('否');
        }
        $('#babyAge').val(obj.babyAge);
        $('#notes').val(obj.babyNote);
        $('#babyWeight').val(obj.babyWeight + 'kg');
        $('#babyHeight').val(obj.babyHeight + 'cm');
        $('#feedHistory').val(obj.feedHistory);
        $('#allergyHistory').val(obj.allergyHistory);
        $('#sickHistory').val(obj.sickHistory);

    }

    $("#restBaby").click(function () {
        window.location.href="/process/regetIllCase?id="+id;
    });

    function getTotalPrice(){
        /****************初始化计算总价****************/
        var formdata = new FormData();
        var jsonarr = new Array();
        var purl = '/process/presettlPrice';

        var countList = new Array();
        $(".countList").each(function () {
            countList.push($(this).val());

        });
        // 单价集合
        var priceList = new Array();
        $(".unitPrice").each(function () {
            priceList.push($(this).val());
        });
        //类型集合
        var typeList = new Array();
        $(".typeList").each(function () {
            typeList.push($(this).val());
        });
        // 名字集合
        var nameList = new Array();
        $(".typeList").each(function () {
            nameList.push($(this).data("name"));
        });
        // 计量单位集合
        var measurewayList = new Array();
        $(".typeList").each(function () {
            measurewayList.push($(this).data("measureway"));
        });
        //reid集合
        var reidList = new Array();
        $(".typeList").each(function () {
            reidList.push($(this).data("reid"));
        });
        //temid集合
        var temidList = new Array();
        $(".typeList").each(function () {
            temidList.push($(this).data("temid"))
        })


        for (var i = 0 ; i < countList.length ; i++){
            var jsonItem = new JsonItem(countList[i],priceList[i],typeList[i],nameList[i],measurewayList[i],reidList[i],temidList[i]);
            var json = JSON.stringify(jsonItem);
            jsonarr.push(json);
        }
        var vipTotal = 0;
        console.log(jsonarr);
        formdata.append("illCaseId",id);
        formdata.append("presDetail",jsonarr.toString());
        $.ajax({
            url: purl,
            type: "POST",
            data: formdata,
            cache: false,
            async: false,
            processData: false,
            contentType: false
        }).done(function (res) {
            console.log(res);
            if(res.success){
                console.log(res.msg);
                vipTotal =  res.data;

            }else {

                   if(res.isEnough){
                       alert(res.msg);
                       if (res.data !="" &&res.data !=null && res.data!=undefined) {
                           vipTotal =  res.data;
                       }else {
                           vipTotal = 0;
                       }
                   }else{
                       if ( res.data !="" && res.data != null && res.data!=undefined ){
                           if(res.data.msg !="" && res.data.msg != null && res.data.msg != undefined){
                               var name = ",";
                               for(var i = 0;i<res.data.enough.length;i++){
                                   name += res.data.enough[i].prename+"、";
                               }
                               alert(res.data.msg+name);
                               vipTotal = 0;
                           }else if(res.data.msg1 != "" && res.data.msg1 != null && res.data.msg1 != undefined){
                               var name;
                               for(var i = 0;i<res.data.noexist.length;i++){
                                   name += res.data.noexist[i].prename+" ";
                               }
                               alert(res.data.msg1+","+name);
                               vipTotal = 0;
                           }
                       }
                   }

            }
            $('#priceID').val(vipTotal);
        });
            // 数量集合
    //     var countList = new Array;
    //     $(".countList").each(function () {
    //         countList.push($(this).val());
    //
    //     });
    //     // 单价集合
    //     var priceList = new Array;
    //     $(".unitPrice").each(function () {
    //         priceList.push($(this).val());
    //     });
    //     console.log(countList.length + "--------" + priceList.length);
        var total = 0;
        for (var i = 0; i < priceList.length; i++) {
            total += parseInt(countList[i]) * parseFloat(priceList[i]);
        }
        return  {normalTotal:total,vipTotal:vipTotal};
     }

     //会员卡类型
    $(function(){
        var url = '/process/getVipCategory';
        var formdata = new FormData();
        formdata.append("illCaseId",id);
        $.ajax({
            url: url,
            type: "POST",
            data: formdata,
            cache: false,
            async: false,
            processData: false,
            contentType: false
        }).done(function (res){
            if(res.success){

                $("#vipCard").html(res.data.vipName);
                $("#vipMoney").html("<span>"+res.money.balance+"</span>")
            }else {
                console.log(res.msg);
            }
        });
    });
</script>
</body>
</html>